package com.xmb.wechat.contact;


import com.xmb.wechat.application.WechatStartApplication;
import com.xmb.wechat.bean.WechatContactBean;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;


public class ContactUtils {


    /**
     * 读取联系人列表并排序
     */
    public static ArrayList<ArrayList<WechatContactBean>> getSortContactList() {
        List<WechatContactBean> dataList =
                WechatStartApplication.getBoxStore().boxFor(WechatContactBean.class).getAll();
        Collections.sort(dataList);
        ArrayList<ArrayList<WechatContactBean>> groupListList = new ArrayList<>();
        ArrayList<WechatContactBean> firstLetterList = new ArrayList<>();
        String letterJin = "#";
        for (int i = 0; i < dataList.size(); i++) {
            WechatContactBean person = dataList.get(i);
            if (!person.getFirstLetter().equals(letterJin)) {
                firstLetterList = new ArrayList<>();
                groupListList.add(firstLetterList);
            }
            firstLetterList.add(person);
            letterJin = person.getFirstLetter();
        }
        return groupListList;
    }


//    /**
//     * 将人名转换为WechatFriendBean类，并放入集合中
//     */
//    public static ArrayList<WechatContactBean> getDataList(Context context, String fileName) {
//        String[] datas = ContactUtils.getDataFromAssets(context, fileName);
//        ArrayList<WechatContactBean> dataList = new ArrayList<>();
//        for (int i = 0; i < datas.length; i++) {
//            dataList.add(new WechatContactBean(datas[i]));
//        }
//        return dataList;
//    }

//    /**
//     * 读取文件，得到人名数组
//     */
//    public static String[] getDataFromAssets(Context context, String fileName) {
//        try {
//            InputStream is = context.getResources().getAssets().open(fileName);
//            BufferedReader tBufferedReader = new BufferedReader(new InputStreamReader(is));
//            StringBuffer sb = new StringBuffer();
//            String strTemp = "";
//            while ((strTemp = tBufferedReader.readLine()) != null) {
//                sb.append(strTemp);
//            }
//            return sb.toString().wechat_split(",");
//        } catch (IOException e) {
//            e.printStackTrace();
//        }
//        return null;
//    }
}
